<?php
// +----------------------------------------------------------------------
// | [KyPHP System] Copyright (c) 2020 http://www.kuryun.com/
// +----------------------------------------------------------------------
// | [KyPHP] 并不是自由软件,你可免费使用,未经许可不能去掉KyPHP相关版权
// +----------------------------------------------------------------------
// | Author: fudaoji <fdj@kuryun.cn>
// +----------------------------------------------------------------------
/**
 * Created by PhpStorm.
 * Script Name: Addon.php
 * Create: 2020/6/29 15:50
 * Description: 应用公共后台控制器
 * Author: fudaoji<fdj@kuryun.cn>
 */
namespace app\common\controller;

class AddonAdmin extends Addon
{
    protected $adminId;
    protected $adminInfo;
    protected $mpInfo = [];
    protected $needAdminLogin = true;

    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->needAdminLogin && $this->isLogin();
    }

    /**
     * check if login
     * Author: fudaoji<fdj@kuryun.cn>
     */
    protected function isLogin(){
        $this->adminId = (int)session("adminId");
        $this->adminInfo = model("common/admin")->getOne($this->adminId);
        if (empty($this->adminInfo)) {
            echo "请先登录";exit;
        }
    }

    /**
     * 公众号/小程序信息
     * @return array
     * Author: fudaoji<fdj@kuryun.cn>
     */
    protected function getMpInfo(){
        $this->mpInfo = model('common/mp')->getOne($this->mid);
        if(empty($this->mpInfo)){
            $this->mpInfo = model('common/mini')->getOne($this->mid);
        }
        return $this->mpInfo;
    }
}